package de.enough.polish.sample.rss;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;



/**
 * <p>Shows RSS news feeds</p>
 *
 * <p>Copyright Enough Software 2007 - 2008</p>
 * @author Robert Virkus, j2mepolish@enough.de
 */
public class WEEMainMidlet extends MIDlet implements CommandListener
{    
    List menuScreen;
    Command enterApplicationCmd = new Command("Enter", Command.ITEM, 8);
    Command quitCmd = new Command( "Quit", Command.EXIT, 10 );
    Display display;
    WEELoginMidlet login;
    
    public WEEMainMidlet()
    {
        super();
        //#style mainMenu
        this.menuScreen = new List("Welcome WEE", List.IMPLICIT);
        //#style mainMenuItem
        this.menuScreen.append( "Mail", null );
        //#style mainMenuItem
        this.menuScreen.append( "Walkee-Talkee", null );
        //#style mainMenuItem
        this.menuScreen.append( "OutDoor Mode", null );
        //#style mainMenuItem
        this.menuScreen.append( "Quit", null );
        
        this.menuScreen.addCommand( this.enterApplicationCmd );
        this.menuScreen.addCommand( this.quitCmd );
        this.menuScreen.setCommandListener( this );
        
    }
    
    public void startApp()throws MIDletStateChangeException {
        this.display = Display.getDisplay( this );
        this.display.setCurrent( this.menuScreen );
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional)throws MIDletStateChangeException {
    }

    public void commandAction(Command cmd, Displayable screen) {
        if(screen == this.menuScreen)
        {
            if(cmd == List.SELECT_COMMAND)
            {
                int selectedItem = this.menuScreen.getSelectedIndex();
                if ( selectedItem == 3 ) 
                    notifyDestroyed();
                if( selectedItem < 3 )
                {
                   login = new WEELoginMidlet();
                   ///#style loginForm
                   this.display.setCurrent(login.returnLoginScreen());
                }
            }
            else if ( cmd == this.quitCmd ) {
                notifyDestroyed();
            }
        }
    }

    
}